package com.engine.common.util.CacheUtil;

import com.engine.common.baseEntity.gis.BoxRangeEntity;
import com.engine.common.util.GeoUtil.GeomCaculateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCache;

import java.util.ArrayList;
import java.util.List;

/**
 * @author FY
 * @version 1.0.0
 * @ClassName CatchUtil.java
 * @Description TODO
 * @createTime 2021年10月22日
 */
@Slf4j
public class MyCacheUtil {

    public static void cleanAll(CacheManager cacheManager, String catchName) {
        try {
            CaffeineCache cache = (CaffeineCache) cacheManager.getCache(catchName);
            cache.clear();
        } catch (Exception e) {

        }
    }

    public static void rmBykeyList(CacheManager cacheManager, String catchName,String keyFirstHalf, List<String> keys) {
        try {
            CaffeineCache cache = (CaffeineCache) cacheManager.getCache(catchName);
            for (String key : keys) {
                cache.evictIfPresent(keyFirstHalf+key);
                log.debug("缓存："+keyFirstHalf+key+"被移除");
            }
        } catch (Exception e) {

        }
    }

    public static void rmBykey(CacheManager cacheManager, String catchName,String keyFirstHalf, String key) {
        try {
            CaffeineCache cache = (CaffeineCache) cacheManager.getCache(catchName);
            cache.evictIfPresent(keyFirstHalf+key);
            log.debug("缓存："+keyFirstHalf+key+"被移除");
        } catch (Exception e) {

        }
    }
}
